package {
	import flash.display.Sprite;
	

	public class MapaLab extends Sprite {
		private var laberinto:Array;
		private var mySpeed:int = 10;
		private var myParent:ScreenGame;
		private var myObjeto:Sprite;
		private var myEnd:Sprite;
		public function MapaLab(par:ScreenGame) {
			initLaberinths();
			myParent = par;
			drawLaberinto(laberinto);
		}
		
		private function initLaberinths():void{
			laberinto = new Array();
			
			laberinto = [
							[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],
							[1,0,0,0,0,0,1,0,0,0,1,4,1,3,1,1,1,0,1,0,0,0,3,0,0,1],
							[1,0,1,1,1,0,1,6,1,1,1,0,1,0,0,0,0,0,1,3,1,1,0,1,0,1],
							[1,0,1,3,1,0,1,0,1,0,1,0,1,1,1,0,1,0,1,0,0,1,6,1,0,1],
							[1,2,1,6,1,2,1,0,0,0,0,0,1,4,1,0,1,4,1,1,0,1,4,1,6,1],
							[1,0,1,0,1,0,1,0,1,1,1,1,1,0,1,0,1,1,1,0,3,1,1,1,0,1],
							[1,0,1,0,1,0,1,0,0,0,0,3,0,0,1,0,1,1,1,0,1,1,1,1,2,1],
							[1,0,1,0,1,0,1,0,1,1,1,1,1,0,1,0,1,2,0,0,0,1,0,0,0,1],
							[1,0,1,2,0,0,0,0,0,2,0,0,1,0,1,0,1,0,1,1,0,1,0,1,1,1],
							[1,0,1,0,1,0,1,1,1,1,1,0,1,0,1,0,1,0,1,1,2,1,6,1,1,1],
							[1,0,1,0,1,0,0,3,0,0,1,0,1,0,1,0,1,0,1,1,0,1,0,0,0,1],
							[1,0,1,0,1,1,1,0,1,0,1,6,1,0,1,0,1,0,1,1,0,1,0,0,0,5],
							[1,0,1,0,1,4,1,0,1,0,1,0,1,0,1,0,0,3,1,1,0,1,0,2,0,1],
							[1,0,0,2,1,0,1,0,1,0,1,2,1,2,4,0,1,0,0,0,0,1,1,1,1,1],
							[1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,1,1,1,0,1,1,1,1,1],
							[1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,1,1,1,0,1,2,0,0,1],
							[1,2,1,0,0,0,1,0,1,0,1,0,1,0,1,0,0,0,3,1,0,0,0,1,0,1],
							[1,0,1,1,1,1,1,0,1,0,1,0,1,0,1,6,1,1,1,1,1,1,1,0,6,1],
							[1,0,1,1,1,1,1,0,1,0,1,0,1,0,1,0,0,2,0,2,0,0,1,6,1,1],
							[1,0,0,0,0,2,0,0,1,3,1,3,0,3,1,4,1,1,1,1,1,3,1,3,0,1],
							[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]];
						 
		}
		
		
		private function drawLaberinto(labe:Array):void{		
			var l:uint = ScreenGame.PIXEL_SIZE;
			
			for (var i:uint = 0; i < labe.length; i++ ) {
				myParent.pool[i] = [];
				for (var j:uint = 0; j < (labe[i] as Array).length; j++) {
//				
					
					switch (labe[i][j]){
						case 0: myObjeto = new Tierra;
//						myObjeto.visible = false; 
						break;
						case 1: myObjeto = new Bloque;					
						myParent.bloques.push(myObjeto);
//						myObjeto.visible = false;
						break;
						case 2: var t:Tierra = new Tierra();
						addChild(t);
						t.x = j*l+l;
						t.y = i*l; 
						t.scaleX = (ScreenGame.PIXEL_SIZE/(t.width));
						t.scaleY = (ScreenGame.PIXEL_SIZE/(t.height));
						myObjeto = new Coin();
						myParent.coins.push(myObjeto);
//						myObjeto.visible = false;
						break;
						case 3: t = new Tierra();
						addChild(t);
						t.x = j*l+l;
						t.y = i*l;
						t.scaleX = (ScreenGame.PIXEL_SIZE/(t.width));
						t.scaleY = (ScreenGame.PIXEL_SIZE/(t.height));
						myObjeto = new Tiempo();
						myParent.times.push(myObjeto);
//						myObjeto.visible = false;
						break;
						case 4: t = new Tierra();
						addChild(t);
						t.x = j*l+l;
						t.y = i*l;
						t.scaleX = (ScreenGame.PIXEL_SIZE/(t.width));
						t.scaleY = (ScreenGame.PIXEL_SIZE/(t.height));
						myObjeto = new Antorcha();
						myParent.torchs.push(myObjeto);
//						myObjeto.visible = false;
						break;
						case 5: t = new Tierra();
						addChild(t);
						t.x = j*l+l;
						t.y = i*l;
						t.scaleX = (ScreenGame.PIXEL_SIZE/(t.width));
						t.scaleY = (ScreenGame.PIXEL_SIZE/(t.height));
						myObjeto = new Sprite();
						myObjeto.graphics.beginFill(0xFF00FF);
						myObjeto.graphics.drawRect(x+75, y, 25, 100);
						myObjeto.graphics.endFill();
						myObjeto.visible = false;
						myEnd = myObjeto;
						break;
						case 6: t = new Tierra();
						addChild(t);
						t.x = j*l+l;
						t.y = i*l;
						t.scaleX = (ScreenGame.PIXEL_SIZE/(t.width));
						t.scaleY = (ScreenGame.PIXEL_SIZE/(t.height));
						myObjeto = new LanzasH(myParent);
						myParent.trapsH.push(myObjeto);break;
					}
					addChild(myObjeto);
					myObjeto.x = j*l+l;
					myObjeto.y = i*l;
					if (!(labe[i][j] == 5)){
						myObjeto.scaleX = (ScreenGame.PIXEL_SIZE/(myObjeto.width));
						myObjeto.scaleY = (ScreenGame.PIXEL_SIZE/(myObjeto.height));
					}
//					myObjeto.scaleX = 0.5;
//					myObjeto.scaleY = 0.5;
//					myParent.pool[i][j] = myObjeto;
					
				}
			}
			
		}
		public function get objeto():Sprite{
			return myObjeto;
		}
		public function get speed():int{
			return mySpeed;
		}
		public function set speed(value:int):void{
			mySpeed = value;
		}
		public function get end():Sprite{
			return myEnd;
		}
	}
}